package com.njwb.day08;

public class TestReg {
    public static void main(String[] args) {
        String str="hello";
        boolean b=str.matches("hello");
        System.out.println(b);

        str="e";
        String regex="[abc]";
        //给定字符串是否是指定正则(Node、b、c)其中之一
        System.out.println(str.matches(regex));//false
        str="b";
        System.out.println(str.matches(regex));//true
        //给定字符串是否是指定正则(d、e、f、g)其中之一
        regex="[defg]";
        str="b";
        System.out.println(str.matches(regex));//false
        System.out.println("d".matches(regex));//true
        //给定字符串不在指定正则(d、e、f、g)其中之一
        regex="[^defg]";
        System.out.println("Node".matches(regex));//true
        System.out.println("e".matches(regex));//false
        System.out.println("g".matches(regex));//false
        System.out.println("1".matches(regex));//true
        System.out.println("+".matches(regex));//true
        System.out.println("=".matches(regex));//true
        regex="[A-Z]";//A到Z之间任意
        System.out.println("A".matches(regex));//true
        System.out.println("E".matches(regex));//true
        System.out.println("G".matches(regex));//true
        System.out.println("1".matches(regex));//false
        System.out.println("+".matches(regex));//false
        System.out.println("Node".matches(regex));//false
        System.out.println("r".matches(regex));//false
        regex="[A-G]";//A到G之间任意
        System.out.println("A".matches(regex));//true
        System.out.println("E".matches(regex));//true
        System.out.println("G".matches(regex));//true
        System.out.println("H".matches(regex));//false
        regex="[0-9]";//0-9之间任意
        System.out.println("A".matches(regex));//false
        System.out.println("E".matches(regex));//false
        System.out.println("G".matches(regex));//false
        System.out.println("1".matches(regex));//true
        System.out.println("+".matches(regex));//false
        System.out.println("Node".matches(regex));//false
        System.out.println("r".matches(regex));//false
        //在1-3范围
        regex="[1-3]";
        System.out.println("2".matches(regex));//true
        System.out.println("3".matches(regex));//true
        System.out.println("4".matches(regex));//false
        regex="[^1-3]";//不在1到3之间任意
        System.out.println("2".matches(regex));//false
        System.out.println("3".matches(regex));//false
        System.out.println("4".matches(regex));//true
        regex="[0-9&&[589]]";//0到9的数字必须是5、8、9其中之一
        System.out.println("2".matches(regex));//false
        System.out.println("3".matches(regex));//false
        System.out.println("4".matches(regex));//false
        System.out.println("5".matches(regex));//true
        System.out.println("6".matches(regex));//false
        System.out.println("8".matches(regex));//true
        regex="\\d";//0-9之间任意
        System.out.println("A".matches(regex));//false
        System.out.println("E".matches(regex));//false
        System.out.println("G".matches(regex));//false
        System.out.println("1".matches(regex));//true
        System.out.println("+".matches(regex));//false
        System.out.println("Node".matches(regex));//false
        System.out.println("r".matches(regex));//false
        regex=".";//任意字符
        System.out.println("Z".matches(regex));//true
        System.out.println("d".matches(regex));//true
        System.out.println("1".matches(regex));//true
        System.out.println("-".matches(regex));//true
        regex="\\.";//只匹配字符的.
        System.out.println("Z".matches(regex));//false
        System.out.println("d".matches(regex));//false
        System.out.println("1".matches(regex));//false
        System.out.println("-".matches(regex));//false
        System.out.println(".".matches(regex));//true
        str="aab";
        //regex="[Node][Node][b]";
        regex="[a-z][abc].";
        System.out.println(str.matches(regex));//true
        System.out.println("xc+".matches(regex));//true
        System.out.println("Ac+".matches(regex));//false
        System.out.println("ad+".matches(regex));//false
        //任意数字出现一次或者一次都没有
        regex="[0-9]?";
        System.out.println("5".matches(regex));//true
        System.out.println("132134".matches(regex));//false
        System.out.println("".matches(regex));//true
        System.out.println("+".matches(regex));//false
        //任意A-G出现一次或者多次
        regex="[A-G]+";
        System.out.println("5".matches(regex));//false
        System.out.println("132134".matches(regex));//false
        System.out.println("".matches(regex));//false
        System.out.println("+".matches(regex));//false
        System.out.println("E".matches(regex));//true
        System.out.println("EFG".matches(regex));//true
        System.out.println("EFGH".matches(regex));//false
        //5个长度的3到8数字
        regex="[3-8]{5}";
        System.out.println("34555".matches(regex));//true
        System.out.println("4555".matches(regex));//false
        System.out.println("455555".matches(regex));//false
        //至少5个长度的3到8数字
        regex="[3-8]{5,}";
        System.out.println("34555".matches(regex));//true
        System.out.println("4555".matches(regex));//false
        System.out.println("455555".matches(regex));//true
        //长度为3到8的3到8的数字
        regex="[3-8]{3,8}";
        System.out.println("34555".matches(regex));//true
        System.out.println("4555".matches(regex));//true
        System.out.println("455555".matches(regex));//true
        System.out.println("451555".matches(regex));//false
        System.out.println("45555566666".matches(regex));//false
        System.out.println("45".matches(regex));//false
        //要么是数字要么是小写英文
        regex="[0-9]|[a-z]";
        System.out.println("3".matches(regex));//true
        System.out.println("x".matches(regex));//true
        System.out.println("45".matches(regex));//false
        System.out.println("ab".matches(regex));//false
        //要么是多个数字要么是多个小写英文
        regex="[0-9]+|[a-z]+";
        System.out.println("3".matches(regex));//true
        System.out.println("x".matches(regex));//true
        System.out.println("45".matches(regex));//true
        System.out.println("ab".matches(regex));//true
        //第一个位置任意大写英文后跟（任意一个数字或者多个小写英文）
        regex="[A-Z]([0-9]|[a-z]+)";
        System.out.println("X1".matches(regex));//true
        System.out.println("X12".matches(regex));//false
        System.out.println("a1".matches(regex));//false
        System.out.println("Dsadasdsa".matches(regex));//true
        System.out.println("Ds".matches(regex));//true
        System.out.println("=================================");
        /*
            字符串：
            Kzcx3244235455@qq.com
            Gxc4535671246@qq.cn
            Dzcx3244235455@sina.com
            Axc4535671246@sina.cn
            Xzcx3244235455@163.com
            Rxc4535671246@163.cn
         */
        regex="[A-Z][a-z]{2,3}\\d{10}@(qq|sina|163)\\.(com|cn)";
        System.out.println("Kzcx3244235455@qq.com".matches(regex));
        System.out.println("Gxc4535671246@qq.cn".matches(regex));
        System.out.println("Dzcx3244235455@sina.com".matches(regex));
        System.out.println("Axc4535671246@sina.cn".matches(regex));
        System.out.println("Xzcx3244235455@163.com".matches(regex));
        System.out.println("Rxc4535671246@163.cn".matches(regex));


        int i=10;
    }
}
